﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ArmoryData.Character;
using System.IO;
using System.Windows;
using System.Windows.Controls;

namespace ArmoryViewer.Controls
{
    /// <summary>
    /// Interaction logic for ItemTooltip.xaml
    /// </summary>
    public partial class ItemTooltip : System.Windows.Controls.UserControl
    {
        string itemTemplate = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/><link rel=\"stylesheet\" type=\"text/css\" href=\"http://static.wowhead.com/css/basic.css?669\" /><link rel=\"stylesheet\" type=\"text/css\" href=\"http://static.wowhead.com/css/global.css?669\" /><link rel=\"stylesheet\" type=\"text/css\" href=\"http://static.wowhead.com/css/locale_enus.css?669\" /><link rel=\"stylesheet\" type=\"text/css\" href=\"http://static.wowhead.com/css/Book.css?669\" /><!--[if IE]><link rel=\"stylesheet\" type=\"text/css\" href=\"http://static.wowhead.com/css/global_ie.css?669\" /><![endif]--><!--[if lte IE 6]><link rel=\"stylesheet\" type=\"text/css\" href=\"http://static.wowhead.com/css/basic_ie6.css?669\" /><link rel=\"stylesheet\" type=\"text/css\" href=\"http://static.wowhead.com/css/global_ie6.css?669\" /><![endif]--><!--[if lte IE 7]><link rel=\"stylesheet\" type=\"text/css\" href=\"http://static.wowhead.com/css/basic_ie67.css?669\" /><link rel=\"stylesheet\" type=\"text/css\" href=\"http://static.wowhead.com/css/global_ie67.css?669\" /><![endif]--><script src=\"http://static.wowhead.com/js/3rdparty/jquery-1.4.js?669\" type=\"text/javascript\"></script><script src=\"http://static.wowhead.com/js/3rdparty/jquery-ui-1.7.2.js?669\" type=\"text/javascript\"></script><script src=\"http://static.wowhead.com/js/3rdparty/swfobject-2.2.js?669\" type=\"text/javascript\"></script><script src=\"http://static.wowhead.com/js/locale_enus.js?669\" type=\"text/javascript\"></script><script src=\"http://static.wowhead.com/js/basic.js?669\" type=\"text/javascript\"></script><script src=\"http://static.wowhead.com/js/global.js?669\" type=\"text/javascript\"></script><script src=\"http://static.wowhead.com/js/Markup.js?669\" type=\"text/javascript\"></script><script src=\"http://static.wowhead.com/js/Mapper.js?669\" type=\"text/javascript\"></script><script src=\"http://static.wowhead.com/widgets/power.js?669\" type=\"text/javascript\"></script><script src=\"http://static.wowhead.com/js/Book.js?669\" type=\"text/javascript\"></script><script src=\"http://www.wowhead.com/?data=user&amp;1266035159\" type=\"text/javascript\"></script><script type=\"text/javascript\">//<![CDATA[var g_serverTime = new Date('2010/02/12 22:25:59');//]]></script></head><body>{0}<br /><img src=\"http://www.wowhead.com/images/badge_88x31.gif\" width=\"88\" height=\"31\" border=\"0\" alt=\"\" /></body></html>";
        public UIElement[] Replacing { get; set; }
        public int Slot { get; set; }
        public ItemTooltip(Item item)
        {
            InitializeComponent();

            string toolTipFile = App.PreferredDirectory + "tooltip.html";
            Slot = item.Slot;
            try
            {
                if (File.Exists(toolTipFile)) File.Delete(toolTipFile);
                FileStream fs = new FileStream(toolTipFile, FileMode.Create, FileAccess.Write);
                StreamWriter file = new StreamWriter(fs);
                file.Write(string.Format(itemTemplate, item.HtmlTooltip));
                file.Close();
                fs.Close();
                webBrowser1.Navigate(toolTipFile.Replace(Path.PathSeparator, '/'));
            }
            catch
            {
                return;
            }
        }
    }
}
